require(["../../conf/config.js"], () => { //
	require(["jquery", "swiper", "common", "template", "jquery-ui"], function($, Swiper, com, Tmplt, ui) {
		// 轮播图
		var mySwiper = new Swiper('.swiper-container', {
			// direction: 'vertical', // 垂直切换选项
			loop: true, // 循环模式选项
			// 如果需要分页器
			pagination: {
				el: '.swiper-pagination',
				clickable: true,
			},
			autoplay: { 
				delay: 3000
			},
			// 如果需要前进后退按钮
			navigation: {
				nextEl: '.swiper-button-next',
				prevEl: '.swiper-button-prev',
			},
		}) 
		$(".swiper-wrapper").on("mouseenter", function() {
			mySwiper.autoplay.stop();
		});
		$(".swiper-wrapper").on("mouseleave", function() {
			mySwiper.autoplay.start();
		})
		mySwiper.el.onmouseover = function() {
			mySwiper.navigation.$nextEl.removeClass('hide');
			mySwiper.navigation.$prevEl.removeClass('hide');
		}
		//鼠标覆盖停止自动切换与隐藏前进后退按钮
		mySwiper.el.onmouseout = function() {
			mySwiper.navigation.$nextEl.addClass('hide');
			mySwiper.navigation.$prevEl.addClass('hide');
		}
		$.ajax({ //城市
			url: "http://localhost:8000/hyg",
			success: function(data) {
				console.log(data.HotCity[0].AreaName);
				let cityhot = document.getElementById("city-hot");
				let htmlstr1 = Tmplt("hotcity", {
					data
				});
				cityhot.innerHTML += htmlstr1;

				// console.log(data.City1.A);
				// for(let i in data.City1 ){
				// 	for(let j in data.City1[i]){
				// 		console.log(data.City1[i][j].AreaName);
				// 	}
				// 	
				// }
				let city1 = document.getElementById("city1");
				let htmlstr2 = Tmplt("Cty1", {
					data
				});
				city1.innerHTML += htmlstr2;

				let city2 = document.getElementById("city2");
				let htmlstr3 = Tmplt("Cty2", {
					data
				});
				city2.innerHTML += htmlstr3;
				
				let city3 = document.getElementById("city3");
				let htmlstr4 = Tmplt("Cty3", {
					data
				});
				city3.innerHTML += htmlstr4;
				
				let city4 = document.getElementById("city4");
				let htmlstr5 = Tmplt("Cty4", {
					data
				});
				city4.innerHTML += htmlstr5;
				
				let city5 = document.getElementById("city5");
				let htmlstr6 = Tmplt("Cty5", {
					data
				});
				city5.innerHTML += htmlstr6;
			}
		})
		$(".citytab span:eq(0)").mouseover(function() {
			$("#city1").addClass('block');
			$("#city2").removeClass('block');
			$("#city3").removeClass('block');
			$("#city4").removeClass('block');
			$("#city5").removeClass('block');
		})
		$(".citytab span:eq(1)").mouseover(function() {
			$("#city1").removeClass('block');
			$("#city2").addClass('block');
			$("#city3").removeClass('block');
			$("#city4").removeClass('block');
			$("#city5").removeClass('block');
		})
		$(".citytab span:eq(2)").mouseover(function() {
			$("#city3").addClass('block');
			$("#city1").removeClass('block');
			$("#city2").removeClass('block');
			$("#city5").removeClass('block');
			$("#city4").removeClass('block');
		})
		$(".citytab span:eq(3)").mouseover(function() {
			$("#city4").addClass('block');
			$("#city1").removeClass('block');
			$("#city2").removeClass('block');
			$("#city5").removeClass('block');
			$("#city3").removeClass('block');
		})
		$(".citytab span:eq(4)").mouseover(function() {
			$("#city5").addClass('block');
			$("#city1").removeClass('block');
			$("#city2").removeClass('block');
			$("#city3").removeClass('block');
			$("#city4").removeClass('block');
		})
		$(".shopping-cart").mouseover(function(){
			$(".shopping-list").show();
		})
		$(".shopping-cart").mouseout(function(){
			$(".shopping-list").hide();
		})
		$(".catalogs-list .item").mouseover(function(){
			$(this).children(".sub-item").show();
		})
		$(".catalogs-list .item").mouseout(function(){
			$(this).children(".sub-item").hide();
		})
		$(".city").mouseenter(function(){
			$
			$(".city-name").children(".s1").toggleClass('Rotate');
		})
		$(".city").mouseleave(function(){
			$(".city-name").children(".s1").toggleClass('Rotate');
		})
		//搜索框
		$("#searchInput").autocomplete({
			source: function(request, response) {
				console.log(request);
				$.ajax({
					url: "http://search.yiguo.com/ajax/fullsearch.ashx",
					dataType: "jsonp", 
					data: { 
						term : request.term
					},
					jsonp: "jsoncallback",
					success: function(data) {
						console.log(data);
						response(data);
					}
				});
			},
			select: function(event, ui) {
				alert(ui.item.value);
			}
		});
	})

});
